﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;

namespace DBUtility.Standard
{
    public interface IDBHelper
    {
        /// <summary>
        /// 创建数据库连接
        /// </summary>
        /// <returns></returns>
        void CreateConnection();

        /// <summary>
        /// 执行Transact-SQL语句并返回受影响的行数
        /// </summary>
        /// <param name="cmdType">命令字符串类型</param>
        /// <param name="cmdText">执行语句</param>
        /// <param name="cmdParams">命令参数列表</param>
        /// <returns>返回int类型</returns>
        int ExecuteNonQuery(CommandType cmdType, string cmdText, params DbParameter[] cmdParams);

        /// <summary>
        /// 在事务中执行Transact-SQL语句并返回受影响的行数
        /// </summary>
        /// <param name="trans">事务</param>
        /// <param name="cmdType">命令字符串类型</param>
        /// <param name="cmdText">执行语句</param>
        /// <param name="cmdParams">命令参数列表</param>
        /// <returns>返回int类型</returns>
        int ExecuteNonQuery(DbTransaction trans, CommandType cmdType, string cmdText, params DbParameter[] cmdParams);

        /// <summary>
        /// 执行Transact-SQL语句并返回数据集DataSet
        /// </summary>
        /// <param name="cmdType">命令字符串类型</param>
        /// <param name="cmdText">执行语句</param>
        /// <param name="cmdParams">命令参数列表</param>
        /// <returns>返回DataSet集合</returns>
        DataSet ExecuteQuery(CommandType cmdType, string cmdText, params DbParameter[] cmdParams);

        /// <summary>
        /// 在事务中执行Transact-SQL语句并返回数据集DataSet
        /// </summary>
        /// <param name="trans">事务</param>
        /// <param name="cmdType">命令字符串类型</param>
        /// <param name="cmdText">执行语句</param>
        /// <param name="cmdParams">命令参数列表</param>
        /// <returns>返回DataSet集合</returns>
        DataSet ExecuteQuery(DbTransaction trans, CommandType cmdType, string cmdText, params DbParameter[] cmdParams);

        /// <summary>
        /// 执行Transact-SQL语句返回内存中数据的一个表
        /// </summary>
        /// <param name="cmdType">命令字符串类型</param>
        /// <param name="cmdText">执行语句</param>
        /// <param name="cmdParams">命令参数列表</param>
        /// <returns>返回内存中数据的一个表</returns>
        DataTable ExecuteNQuery(CommandType cmdType, string cmdText, params DbParameter[] cmdParams);

        /// <summary>
        /// 在事务中执行Transact-SQL语句返回内存中数据的一个表
        /// </summary>
        /// <param name="trans">事务</param>
        /// <param name="cmdType">命令字符串类型</param>
        /// <param name="cmdText">执行语句</param>
        /// <param name="cmdParams">命令参数列表</param>
        /// <returns>返回内存中数据的一个表</returns>
        DataTable ExecuteNQuery(DbTransaction trans, CommandType cmdType, string cmdText, params DbParameter[] cmdParams);

        /// <summary>
        /// 执行Transact-SQL语句返回List<List<string>>
        /// </summary>
        /// <param name="cmdType">命令字符串类型</param>
        /// <param name="cmdText">执行语句</param>
        /// <param name="cmdParams">命令参数列表</param>
        /// <returns></returns>
        List<List<string>> ExecuteLQuery(CommandType cmdType, string cmdText, params DbParameter[] cmdParams);

        /// <summary>
        /// 在事务中执行Transact-SQL语句返回List<List<string>>
        /// </summary>
        /// <param name="trans">事务</param>
        /// <param name="cmdType">命令字符串类型</param>
        /// <param name="cmdText">执行语句</param>
        /// <param name="cmdParams">命令参数列表</param>
        /// <returns></returns>
        List<List<string>> ExecuteLQuery(DbTransaction trans, CommandType cmdType, string cmdText, params DbParameter[] cmdParams);

        /// <summary>
        /// 执行查询，返回DataReader
        /// </summary>
        /// <param name="cmdType">命令字符串类型</param>
        /// <param name="cmdText">执行语句</param>
        /// <param name="cmdParams">命令参数列表</param>
        /// <returns>返回DataReader</returns>
        DbDataReader ExecuteReader( CommandType cmdType, string cmdText, params DbParameter[] cmdParams);

        /// <summary>
        /// 在事务中执行执行查询，返回DataReader
        /// </summary>
        /// <param name="trans">事务</param>
        /// <param name="cmdType">命令字符串类型</param>
        /// <param name="cmdText">执行语句</param>
        /// <param name="cmdParams">命令参数列表</param>
        /// <returns>返回DataReader</returns>
        DbDataReader ExecuteReader(DbTransaction trans, CommandType cmdType, string cmdText, params DbParameter[] cmdParams);

        /// <summary>
        /// 执行查询，返回结果集中的第一行第一列，忽略其它行其它列
        /// </summary>
        /// <param name="cmdType">命令字符串类型</param>
        /// <param name="cmdText">执行语句</param>
        /// <param name="cmdParams">命令参数列表</param>
        /// <returns>返回结果集中的第一行第一列，忽略其它行其它列</returns>
        object ExecuteScalar(CommandType cmdType, string cmdText, params DbParameter[] cmdParams);

        /// <summary>
        /// 在事务中执行查询，返回结果集中的第一行第一列，忽略其它行其它列
        /// </summary>
        /// <param name="trans">事务</param>
        /// <param name="cmdType">命令字符串类型</param>
        /// <param name="cmdText">执行语句</param>
        /// <param name="cmdParams">命令参数列表</param>
        /// <returns>返回结果集中的第一行第一列，忽略其它行其它列</returns>
        object ExecuteScalar(DbTransaction trans, CommandType cmdType, string cmdText, params DbParameter[] cmdParams);

        /// <summary>
        /// 返回DbParameter的对象
        /// </summary>
        /// <param name="paramName">参数名称</param>
        /// <param name="dbType">参数类型</param>
        /// <param name="value">参数值</param>
        /// <param name="size">参数大小</param>
        /// <param name="direction">参数值方向</param>
        /// <returns></returns>
        DbParameter CreateParam(string paramName, DbType dbType, object value, int size, ParameterDirection direction);

        /// <summary>
        /// 返回一个输入类型的DbParameter对象
        /// </summary>
        /// <param name="paramName">参数名称</param>
        /// <param name="dbType">参数类型</param>
        /// <param name="value">参数值</param>
        /// <param name="size">参数大小</param>
        /// <returns></returns>
         DbParameter CreateInParam(string paramName, DbType dbType, object value, int size);

        /// <summary>
        /// 返回一个输入类型的DbParameter对象
        /// </summary>
        /// <param name="paramName">参数名称</param>
        /// <param name="dbType">参数类型</param>
        /// <param name="value">参数值</param>
        /// <returns></returns>
        DbParameter CreateInParam(string paramName, DbType dbType, object value);

        /// <summary>
        /// 返回一个输出类型的DbParameter对象
        /// </summary>
        /// <param name="paramName">参数名称</param>
        /// <param name="dbType">参数类型</param>
        /// <param name="size">参数大小</param>
        /// <returns></returns>
        DbParameter CreateOutParam(string paramName, DbType dbType, int size);

        /// <summary>
        /// 返回一个输出类型的DbParameter对象
        /// </summary>
        /// <param name="paramName">参数名称</param>
        /// <param name="dbType">参数类型</param>
        /// <returns></returns>
        DbParameter CreateOutParam(string paramName, DbType dbType);

        /// <summary>
        /// 返回一个返回类型的DbParameter对象
        /// </summary>
        /// <param name="paramName">参数名称</param>
        /// <param name="dbType">参数类型</param>
        /// <param name="size">参数大小</param>
        /// <returns></returns>
        DbParameter CreateReturnParam(string paramName, DbType dbType, int size);

        /// <summary>
        ///  返回一个返回类型的DbParameter对象
        /// </summary>
        /// <param name="paramName">参数名称</param>
        /// <param name="dbType">参数类型</param>
        /// <returns></returns>
        DbParameter CreateReturnParam(string paramName, DbType dbType);
    }
}
